from google.appengine.ext.webapp import RequestHandler, template
from google.appengine.ext import db
import handler.config as config
from model.token import OAuthRequestToken
import logging
import pickle
import tweepy

class SignupPage(RequestHandler):
    def get(self):
        url = self.request.url
        auth = tweepy.OAuthHandler(config.get_consumer_key(url), 
                                   config.get_consumer_secret(url), 
                                   None)
        try:
            print template.render(
                'view/signup.html', 
                {"authurl": auth.get_authorization_url()})
        except tweepy.TweepError, e:
            print template.render('view/error.html', {'message': e})
            return

        request_token = OAuthRequestToken(
            token_key = auth.request_token.key,
            token_secret = auth.request_token.secret)
        request_token.put()